var nums = [-1, 0, 3, 5, 9, 12];

var target = 9;

var search = function (nums, target) {
    console.log(target, nums[nums.length / 2])
    if (target == nums[nums.length / 2]) {
        return nums.length / 2
    }
    else if (target < nums[nums.length / 2]) {
        for (var i = nums.length / 2 -1; i >= 0; i--) {
            console.log(nums[i])
            if (target == nums[i]) {
                return i
            }
        }
    } else {
        for (var i = nums.length / 2 + 1; i < nums.length; i++) {
            if (target == nums[i]) {
                return i
            }
        }
    }

}

console.log(search(nums, target))